/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;

namespace DiggApiNet
{
    public class DiggEvents : DiggReturnBaseCollection, IEnumerable
    {
        private List<DiggEvent> _events;
        public List<DiggEvent> Events
        {
            get
            {
                return _events;
            }
            set
            {
                _events = value;
            }
        }
        public DiggEvent this[int index]
        {
            get
            {
                return _events[index];
            }
            set
            {
                _events[index] = value;
            }
        }

        public DiggEvents()
        {
            _events = new List<DiggEvent>();
        }
        public DiggEvents(XmlDocument xml_doc) : base(xml_doc, "events")
        {
            _events = new List<DiggEvent>();
            if (xml_doc.SelectSingleNode("events") == null
                || xml_doc.SelectSingleNode("events").SelectNodes("digg") == null) {
                throw new DiggApiException("XML response appears to be malformed, or contains unexpected data.");
            }
            foreach (XmlNode node in xml_doc.SelectSingleNode("events").SelectNodes("digg")) {
                _events.Add(new DiggEvent(node));
            }
        }

        public IEnumerator GetEnumerator()
        {
            return _events.GetEnumerator();
        }
    }
}
